<template>
  <div class="kuwei">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">质检规则管理</span>
        <el-button style="float: right;" type="primary" @click="dialogOpen('add')" v-if="USER.auth.indexOf('rule_zhijian_add')!==-1
">新增质检规则</el-button>
      </div>
      <s-table
        :table="table" ref="table" @http="tableWatch" :expand="false">
        <el-table-column
          fixed="right"
          align="center"
          slot="operation"
          class-name="operationMore"
          label="可用操作"
          width="120">
          <template scope="s">
            <el-button type="info" size="mini" @click="dialogSearchOpen(s.row)" icon="search" v-if="USER.auth.indexOf('rule_zhijian_editdetailed')!==-1 && s.row.fs !== '0'"></el-button>
            <el-button type="success" icon="edit" size="mini" @click="dialogEditOpen(s.row)" v-if="USER.auth.indexOf('rule_zhijian_edit')!==-1
"></el-button>
          </template>
        </el-table-column>
        <el-form-item label="规则名称" prop="mc">
          <el-input type="text"
                    class="input"
                    v-model="autoVue_table_mc"
                    placeholder="规则名称" spellcheck="false" auto-capitalize="off" auto-complete="off"
                    auto-correct="off"></el-input>
        </el-form-item>
        <el-form-item label="质检方式" prop="fs">
          <el-select v-model="autoVue_table_fs"
                     placeholder="质检方式">
            <el-option
              label="全部"
              value=""></el-option>
            <el-option
              v-for="item in ZHIJIAN.fs"
              :key="item.dictionaryid"
              :label="item.value"
              :value="item.dictionaryid">
            </el-option>
          </el-select>
        </el-form-item>
      </s-table>
    </el-card>
    <s-dialog :dialog="dialog" :close="dialogInit">
      <p slot="title">{{dialog.title}}质检规则</p>
      <s-form :form="formDialog" ref="formDialog">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="mc" label="规则名称">
              <el-input
                type="text"
                v-model="formDialog.mc"
                placeholder="规则名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="fs" label="质检方式">
              <el-select v-model="formDialog.fs" placeholder="请选择">
                <el-option
                  v-for="item in ZHIJIAN.fs"
                  :key="item.dictionaryid"
                  :label="item.value"
                  :value="item.dictionaryid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <div class="__table">
        <el-button @click="dialogAddOpen('add')" v-if="formDialog.fs !== '0' && formDialog.fs !== '1' " class="__table_button"><i class="el-icon-plus"></i></el-button>
        <s-table :table="tableAdd" ref="tableAdd" @http="tableWatch" :pagination="false" :control="false"  v-if="formDialog.fs != '0' && formDialog.fs != '1'" :expand="false" :index="true">
          <el-table-column
            fixed="right"
            align="center"
            slot="operation"
            class-name="operationMore"
            label="可用操作"
            width="120">
            <template scope="s">
              <el-button type="success" icon="edit" size="mini" @click="tableAddEdit(s.$index,s.row)"></el-button>
              <el-button type="danger" icon="delete" size="mini" @click="tableAddDelete(s.$index)"></el-button>
            </template>
          </el-table-column>
        </s-table>
        <el-button @click="dialogAddOpen('add')" v-if="formDialog.fs !== '0' && formDialog.fs !== '2' " class="__table_button"><i class="el-icon-plus"></i></el-button>
        <s-table :table="tableAdd_1" ref="tableAdd_1" @http="tableWatch" :pagination="false" :control="false"  v-if="formDialog.fs != '0' && formDialog.fs != '2'" :expand="false" :index="true">
          <el-table-column
            fixed="right"
            align="center"
            slot="operation"
            class-name="operationMore"
            label="可用操作"
            width="120">
            <template scope="s">
              <el-button type="success" icon="edit" size="mini" @click="tableAddEdit(s.$index,s.row)"></el-button>
              <el-button type="danger" icon="delete" size="mini" @click="tableAddDelete(s.$index)"></el-button>
            </template>
          </el-table-column>
        </s-table>
      </div>
      <el-button slot="footer" @click="dialogSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogAdd" :close="dialogAddInit">
      <p slot="title">{{dialogAdd.title}}质检规则明细</p>
      <s-form :form="formDialogAdd" ref="formDialogAdd">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="qssl" label="起始数量">
              <el-input
                type="text"
                v-model="formDialogAdd.qssl"
                placeholder="起始数量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="jssl" label="结束数量">
              <el-input
                type="text"
                v-model="formDialogAdd.jssl"
                placeholder="结束数量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" v-if= "formDialog.fs == 1">
            <el-form-item prop="bfb" label="抽检比例(1-100%)">
              <el-input
                type="text"
                v-model="formDialogAdd.bfb"
                placeholder="抽检比例"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" v-if= "formDialog.fs == 2">
            <el-form-item prop="gdsl" label="固定数量">
              <el-input
                type="text"
                v-model="formDialogAdd.gdsl"
                placeholder="固定数量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogAddSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogSearch" :close="dialogSearchInit" :closeTip="false">
      <p slot="title">查看明细<span></span></p>
      <div class="__table">
        <el-button @click="dialogMxOpen()" v-if="this.dialogSearch.row.fs ==='1'" class="__table_button"><i class="el-icon-plus"></i></el-button>
          <s-table :table="tableSearch" ref="tableSearch" v-if="this.dialogSearch.row.fs ==='1'" @http="tableWatch" :pagination="false" :control="false" :expand="false" :index="true">
        </s-table>
     <el-button @click="dialogMxOpen()" v-if="this.dialogSearch.row.fs ==='2'" class="__table_button"><i class="el-icon-plus"></i></el-button>
          <s-table :table="tableSearch_2" ref="tableSearch_2" v-if="this.dialogSearch.row.fs ==='2'" @http="tableWatch" :pagination="false" :control="false" :expand="false" :index="true">
        </s-table>
      </div>
      <el-button slot="footer" @click="dialogSearchSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogMx" :close="dialogMxInit">
      <p slot="title">{{dialogMx.title}}规则明细</p>
      <s-form :form="formDialogMx" ref="formDialogMx">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="qssl" label="起始数量">
              <el-input
                type="text"
                v-model="formDialogMx.qssl"
                placeholder="起始数量"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="jssl" label="结束数量">
              <el-input
                type="text"
                v-model="formDialogMx.jssl"
                placeholder="结束数量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" v-if="this.dialogSearch.row.fs ==='1'">
            <el-form-item prop="bfb" label="抽检比例(1-100%)">
              <el-input
                type="text"
                v-model="formDialogMx.bfb"
                placeholder="抽检比例"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 0}" v-if="this.dialogSearch.row.fs ==='2'">
            <el-form-item prop="gdsl" label="固定数量">
              <el-input
                type="text"
                v-model="formDialogMx.gdsl"
                placeholder="固定数量"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" @click="dialogMxSave">保存</el-button>
    </s-dialog>
    <s-dialog :dialog="dialogEdit" :close="dialogEditInit">
      <p slot="title">{{dialogEdit.title}}质检规则</p>
      <s-form :form="formDialogEdit" ref="formDialogEdit">
        <el-row>
          <el-col :xs="24" :lg="{span: 11, offset: 0}">
            <el-form-item prop="mc" label="规则名称">
              <el-input
                type="text"
                v-model="formDialogEdit.mc"
                placeholder="规则名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 11, offset: 1}">
            <el-form-item prop="fs" label="质检方式">
              <el-select v-model="formDialogEdit.fs" placeholder="请选择" disabled>
                <el-option
                  v-for="item in ZHIJIAN.fs"
                  :key="item.dictionaryid"
                  :label="item.value"
                  :value="item.dictionaryid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </s-form>
      <el-button slot="footer" type="success" @click="dialogEditSave">保存</el-button>
    </s-dialog>
  </div>
</template>
<script>
  import { AutoVue, AutoPromise } from '~/plugins/Tools';

  function __form () {
    return {
      mc: {value: '', rule: ['vNull'], cRemarks: ''},
      fs: {value: '0', rule: ['vNull__change'], cRemarks: '0全检 1百分比 2固定数量'},
    };
  }
  function __formEdit () {
    return {
      mc: {value: '', rule: ['vNull'], cRemarks: ''},
      fs: {value: '0', rule: ['vNull__change'], cRemarks: '0全检 1百分比 2固定数量'},
    };
  }
  function __formAdd () {
    return {
      sx: {value: '', rule: ['vNull'], cRemarks: ''},
      jssl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ', 'vN0Number'], cRemarks: ''},
      qssl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
      gdsl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
      bfb: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ'], cRemarks: ''},
      sl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
    };
  }
  function __formMx () {
    return {
      sx: {value: '', rule: ['vNull'], cRemarks: ''},
      jssl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
      qssl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
      gdsl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
      bfb: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ'], cRemarks: ''},
      sl: {value: '', rule: ['vNull', 'vNumber', 'vNumberZ', 'vNumberZZ'], cRemarks: ''},
    };
  }
  export default AutoVue({
    name: 'base_kuwei-FEcarWms',
    store: ['DICTIONARY_zhijian', 'ZHIJIAN', 'USER'],
    data: {
      table: {
        column: [
          {
            label: '规则名称',
            prop: 'mc',
            minWidth: '0px',
            cRemarks: '',
            search: true,
          },
          {
            label: '货主',
            prop: 'hzmc',
            minWidth: '0px',
            cRemarks: '',
            search: false,
          },
          {
            label: '质检方式',
            prop: 'show_fs',
            minWidth: '0px',
            cRemarks: '0全检 1百分比 2固定数量',
            search: true,
          }],
        url: '/wmsqualitytesting/list',
        key: 'id',
        muti: false,
        tableColumn: 3,
      },
      formDialog: __form(),
      dialog: {
        title: '新增',
        row: {},
        formDialogAdd: {
          row: {},
        },
      },

      tableAdd: {
        column:
          [
            {
              label: '起始数量',
              prop: 'qssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '结束数量',
              prop: 'jssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '固定数量',
              prop: 'gdsl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '抽检比例',
              prop: 'bfb',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return row[column.property || column] + '%';
              },
              search: false,
            },
            {
              label: '顺序',
              prop: 'sx',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
          ],
        key: 'id',
        muti: false,
        tableColumn: 3,
      },
      tableAdd_1: {
        column:
          [
            {
              label: '起始数量',
              prop: 'qssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '结束数量',
              prop: 'jssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '抽检比例',
              prop: 'bfb',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return row[column.property || column] + '%';
              },
              search: false,
            },
            {
              label: '固定数量',
              prop: 'gdsl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '顺序',
              prop: 'sx',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
          ],
        key: 'id',
        muti: false,
        tableColumn: 3,
      },
      formDialogAdd: __formAdd(),
      dialogAdd: {
        title: '新增',
      },

      tableSearch: {
        column:
          [
            {
              label: '起始数量',
              prop: 'qssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '结束数量',
              prop: 'jssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '抽检比例',
              prop: 'bfb',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return row[column.property || column] + '%';
              },
              search: false,
            },
            {
              label: '固定数量',
              prop: 'gdsl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '顺序',
              prop: 'sx',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
          ],
        key: 'id',
        tableColumn: 3,
        muti: false,
      },
      tableSearch_2: {
        column:
          [
            {
              label: '起始数量',
              prop: 'qssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '结束数量',
              prop: 'jssl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '固定数量',
              prop: 'gdsl',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
            {
              label: '抽检比例',
              prop: 'bfb',
              minWidth: '0px',
              cRemarks: '',
              formatter: (row, column) => {
                return row[column.property || column] + '%';
              },
              search: false,
            },
            {
              label: '顺序',
              prop: 'sx',
              minWidth: '0px',
              cRemarks: '',
              search: false,
            },
          ],
        key: 'bh',
        tableColumn: 3,
        muti: false,
      },
      dialogSearch: {
        row: {},
      },

      dialogMx: {
        title: '新增',
      },
      formDialogMx: __formMx(),

      dialogEdit: {
        title: '编辑',
      },
      formDialogEdit: __formEdit(),
    },
    transition: 'slide-fade',
    methods: {
      dialogInit () {
        this.formDialog = {
          ...this.formDialog,
          ...this.ObjectClone(__form()),
        };
        this.resetFields('formDialog');
        // 重置table列表
        this.tableClear('tableAdd');
        this.tableClear('tableAdd_1');
      },
      async dialogOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        await AutoPromise([
          async () => {
            if (!this.DICTIONARY_zhijian) {
              await this.USE('DICTIONARY_zhijian');
            }
          },
        ]);
        switch (type) {
        case 'ADD':
          this.dialog.title = '新增';
          this.formDialog.id = 0;
          break;
        case 'PUT':
          this.dialog.title = '修改';
          this.formDialog = {
            ...this.formDialog,
            ...this.ObjectClone(__form(), row),
          };
          this.dialog.row = row;
          break;
        }
        this.dialog.visible = true;
      },
      dialogSave () {
        this.VALIDATE('formDialog', async option => {
          if (this.formDialog.fs === '0') {
            let json = {
              ...this.FORMOPTION('formDialogAdd'),
              ...option,
            };
            try {
              await this.post('/wmsqualitytesting/add', json);
              this.dialogInit();
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
          if (this.formDialog.fs === '1') {
            if (this.tableAdd_1.data.length < 1) {
              return this.$alert('新增 质检规则 中 明细不能为空', '提示');
            }
            for (let i = 0; i < this.tableAdd_1.data.length; i++) {
              this.tableAdd_1.data[i].sx = (i + 1);
            }
            let json = {
              ...this.FORMOPTION('formDialogAdd'),
              ...option,
              detailedList: this.tableAdd_1.data,
            };
            try {
              console.log('this.tableAdd_1.data:' + this.tableAdd_1.data);
              console.log('json.detailedList:' + json.detailedList);
              await this.post('/wmsqualitytesting/add', json);
              this.dialogInit();
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
          if (this.formDialog.fs === '2') {
            if (this.tableAdd.data.length < 1) {
              return this.$alert('新增 质检规则 中 明细不能为空！', '提示');
            }
            for (let i = 0; i < this.tableAdd.data.length; i++) {
              this.tableAdd.data[i].sx = (i + 1);
            }
            let json1 = {
              ...this.FORMOPTION('formDialogAdd'),
              ...option,
              detailedList: this.tableAdd.data,
            };
            try {
              await this.post('/wmsqualitytesting/add', json1);
              this.dialogInit();
              this.tableWatch('table');
              this.dialog.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
        });
      },

      tableAddEdit (index, row) {
        // 获取当前行 //输出object
        console.log('row:' + row);
        // 获取当前行的index
        console.log('index:' + index);
        this.dialog.row = row;
        console.log('this.dialog.row:' + this.dialog.row);
        console.log('this.dialog.row[0]:' + this.dialog.row[0]);
        this.dialogAddOpen('PUT', row);
      },
      tableAddDelete (index) {
        if (this.formDialog.fs === '2') {
          this.$confirm('您将删除选择的质检明细 顺序为： ' + (index + 1), '确认删除？', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
          })
            .then(_ => {
              this.tableAdd.data.splice(index, 1);
            });
        } else {
          this.$confirm('您将删除选择的质检明细 顺序为： ' + (index + 1), '确认删除？', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning',
          })
            .then(_ => {
              this.tableAdd_1.data.splice(index, 1);
            });
        }
      },
      dialogAddInit () {
        this.formDialogAdd = {
          ...this.formDialogAdd,
          ...this.ObjectClone(__formAdd()),
        };
        this.resetFields('formDialogAdd');
      },
      dialogAddOpen (type, row) {
        if (type) {
          type = type.toUpperCase();
        } else return;
        switch (type) {
        case 'ADD':
          this.dialogAdd.title = '新增';
          this.formDialogAdd.id = 0;
          break;
        case 'PUT':
          this.dialogAdd.title = '修改';
          this.formDialogAdd = {
            ...this.formDialogAdd,
            ...this.ObjectClone(__formAdd(), row),
          };
          this.dialogAdd.row = row;
          console.log('111111111111:' + this.dialogAdd.row);
          break;
        }
        this.dialogAdd.visible = true;
      },
      dialogAddSave () {
        if (this.dialogAdd.title === '新增') {
          this.VALIDATE('formDialogAdd', option => {
            if (this.formDialog.fs === '1') {
              if (parseInt(this.formDialogAdd.qssl) > parseInt(this.formDialogAdd.jssl)) {
                return this.$alert('起始数量 不能大于 结束数量', '提示');
              }
              if (this.tableAdd_1.data.length !== 0 && parseInt(option.qssl) < this.tableAdd_1.data[this.tableAdd_1.data.length - 1].jssl) {
                return this.$alert('输入的起始数量要大于前一条的结束数量！', '提示');
              }
              if (parseInt(this.formDialogAdd.qssl) > parseInt(this.formDialogAdd.jssl)) {
                return this.$alert('起始数量 不能大于 结束数量', '提示');
              }
              if (parseInt(this.formDialogAdd.bfb) > 100 || parseInt(this.formDialogAdd.bfb) < 0) {
                return this.$alert('抽检比例 介于0和100之间', '提示');
              }
              // option.bfb = this.formDialogAdd.bfb / 100;
              this.tableAdd_1.data.push(option);
              this.tableAdd_1.total++;
              this.dialogAddInit();
              this.dialogAdd.visible = false;
            }
            if (this.formDialog.fs === '2') {
              if (parseInt(this.formDialogAdd.qssl) > parseInt(this.formDialogAdd.jssl)) {
                return this.$alert('起始数量 不能大于 结束数量', '提示');
              }
              if (parseInt(this.formDialogAdd.gdsl) > parseInt(this.formDialogAdd.jssl)) {
                return this.$alert('固定数量 不能大于 结束数量', '提示');
              }
              if (parseInt(this.formDialogAdd.gdsl) < parseInt(this.formDialogAdd.qssl)) {
                return this.$alert('固定数量 不能小于 起始数量', '提示');
              }
              if (this.tableAdd.data.length !== 0 && parseInt(option.qssl) < this.tableAdd.data[this.tableAdd.data.length - 1].jssl) {
                return this.$alert('输入的起始数量要大于前一条的结束数量！', '提示');
              }
              this.tableAdd.data.push(option);
              this.tableAdd.total++;
              this.dialogAddInit();
              this.dialogAdd.visible = false;
            }
          });
        } else {
          this.VALIDATE('formDialogAdd', option => {
            for (let index in this.dialogAdd.row) {
              if (this.dialogAdd.row.hasOwnProperty(index)) {
                this.dialogAdd.row[index] = option[index];
              }
              if (this.formDialog.fs === '2') {
                if (parseInt(this.formDialogAdd.qssl) > parseInt(this.formDialogAdd.jssl)) {
                  return this.$alert('起始数量 不能大于 结束数量', '提示');
                }
                if (parseInt(this.formDialogAdd.gdsl) > parseInt(this.formDialogAdd.jssl)) {
                  return this.$alert('固定数量 不能大于 结束数量', '提示');
                }
                if (parseInt(this.formDialogAdd.gdsl) < parseInt(this.formDialogAdd.qssl)) {
                  return this.$alert('固定数量 不能小于 起始数量', '提示');
                }
                console.log(this.dialog.row);
                if (this.tableAdd.data.length !== 0 && option.jssl < this.tableAdd.data[index - 1].qssl) {
                  return this.$alert('输入的起始数量要大于前一条的结束数量！', '提示');
                }
              } else {
                if (parseInt(this.formDialogAdd.qssl) > parseInt(this.formDialogAdd.jssl)) {
                  return this.$alert('起始数量 不能大于 结束数量', '提示');
                }
                if (this.tableAdd.data.length !== 0 && option.qssl < this.tableAdd.data[this.tableAdd.data.length - 1].jssl) {
                  return this.$alert('输入的起始数量要大于前一条的结束数量！', '提示');
                }
                if (parseInt(this.formDialogAdd.bfb) > 100 || parseInt(this.formDialogAdd.bfb) < 0) {
                  return this.$alert('抽检比例 介于0和100之间', '提示');
                }
              }
            }
            this.dialogAddInit();
            this.dialogAdd.visible = false;
          });
        }
      },

      dialogSearchInit () {},
      async dialogSearchOpen (row) {
        this.dialogSearch.row = row;
        this.tableSearch.data = await this.get('/wmsqualitytestingdetailed/getDetailList/' + row.id);
        console.log('this.tableSearch.data.length:' + this.tableSearch.data);
        console.log('this.tableSearch.data.length:' + this.tableSearch.data.length);
        this.tableSearch_2.data = await this.get('/wmsqualitytestingdetailed/getDetailList/' + row.id);
        this.dialogSearch.visible = true;
      },
      dialogSearchSave () {
        this.dialogSearch.visible = false;
      },

      dialogMxInit () {
        this.formDialogMx = {
          ...this.formDialogMx,
          ...this.ObjectClone(__formMx()),
        };
        this.resetFields('formDialogMx');
      },
      dialogMxOpen () {
        this.dialogMx.visible = true;
      },
      dialogMxSave () {
        this.VALIDATE('formDialogMx', async option => {
          if (this.dialogSearch.row.fs === '1') {
            if (parseInt(this.formDialogMx.qssl) > parseInt(this.formDialogMx.jssl)) {
              return this.$alert('起始数量 不能大于 结束数量', '提示');
            }
            if (this.tableSearch.data.length !== 0 && parseInt(option.qssl) < this.tableSearch.data[this.tableSearch.data.length - 1].jssl) {
              return this.$alert('输入的起始数量要大于前一条的结束数量！', '提示');
            }
            if (parseInt(this.formDialogMx.qssl) > parseInt(this.formDialogMx.jssl)) {
              return this.$alert('起始数量 不能大于 结束数量', '提示');
            }
            if (parseInt(this.formDialogMx.bfb) > 100 || parseInt(this.formDialogMx.bfb) < 0) {
              return this.$alert('抽检比例 介于0和100之间', '提示');
            }
            try {
              option.sx = this.tableSearch.data.length + 1;
              option.sszjgzid = this.dialogSearch.row.id;
              await this.post('/wmsqualitytestingdetailed/add', option);
              this.tableSearch.data = await this.get('/wmsqualitytestingdetailed/getDetailList/' + this.dialogSearch.row.id);
              this.dialogMxInit();
              this.dialogMx.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
          if (this.dialogSearch.row.fs === '2') {
            if (parseInt(this.formDialogMx.qssl) > parseInt(this.formDialogMx.jssl)) {
              return this.$alert('起始数量 不能大于 结束数量', '提示');
            }
            if (parseInt(this.formDialogMx.gdsl) > parseInt(this.formDialogMx.jssl)) {
              return this.$alert('固定数量 不能大于 结束数量', '提示');
            }
            if (parseInt(this.formDialogMx.gdsl) < parseInt(this.formDialogMx.qssl)) {
              return this.$alert('固定数量 不能小于 起始数量', '提示');
            }
            if (this.tableSearch_2.data.length !== 0 && parseInt(option.qssl) < this.tableSearch_2.data[this.tableSearch_2.data.length - 1].jssl) {
              return this.$alert('输入的起始数量要大于前一条的结束数量！', '提示');
            }
            try {
              option.sx = this.tableSearch.data.length + 1;
              option.sszjgzid = this.dialogSearch.row.id;
              await this.post('/wmsqualitytestingdetailed/add', option);
              this.tableSearch_2.data = await this.get('/wmsqualitytestingdetailed/getDetailList/' + this.dialogSearch.row.id);
              this.dialogMxInit();
              this.dialogMx.visible = false;
            } catch (err) {
              console.log(err);
            }
          }
        });
      },
      dialogEditInit () {
        this.formDialogEdit = {
          ...this.formDialogEdit,
          ...this.ObjectClone(__formEdit()),
        };
        this.resetFields('formDialogEdit');
      },
      async dialogEditOpen (row) {
        await AutoPromise([
          async () => {
            if (!this.DICTIONARY_zhijian) {
              await this.USE('DICTIONARY_zhijian');
            }
          },
        ]);
        this.dialogEdit.row = row;
        this.formDialogEdit = {
          ...this.formDialogEdit,
          ...this.ObjectClone(__formEdit(), row),
        };
        this.dialogEdit.visible = true;
      },
      dialogEditSave () {
        this.VALIDATE('formDialogEdit', async option => {
          option.id = this.dialogEdit.row.id;
          try {
            // 页面上有质检方式，但是在编辑不传这个字段，直接使用delete option.字段名称
            delete option.fs;
            await this.post('/wmsqualitytesting/edit', option);
            this.dialogEditInit();
            this.tableWatch('table');
            this.dialogEdit.visible = false;
          } catch (err) {
            console.log(err);
          }
        });
      },
    },
    mounted: async function () {
      this.tableWatch('table');
      if (!this.DICTIONARY_zhijian) {
        await this.USE('DICTIONARY_zhijian');
      }
    },
  });
</script>
<style scoped lang="scss">
  .box-card {
    margin: 20px;
  }

  .createTimeSpan {
    display: block;
    margin-top: 34px;
  }

  @media screen and (max-width: 800px) {
    .createTimeSpan {
      margin-top: 0;
    }
    .box-card {
      margin: 0;
    }
  }

  .el-select {
    width: 100%;
  }
</style>
